using System;
using System.Collections;
using System.Web.UI.WebControls;
using Sedna.Core.Persistence;
using Iesi.Collections;

namespace Sedna.Core.Controller
{
	public interface IDataGridController: ICloneable
	{
		/// <summary>
		/// Set controlled grid
		/// </summary>
		DataGrid Grid { get; set;}

		/// <summary>
		/// Is this controller support grid page`s cache, edited/added data`s collection
		/// and middle tier`s sort of the binding data collection or not
		/// </summary>
		bool IsAllowTransient { get; set;}

	    /// <summary>
	    /// Whether controller will apply transient data to datagrid's source
	    /// </summary>
        bool IsApplyTransientToDataSource { get; set; }

		/// <summary>
		/// Path to the <c>TransientData</c> collection
		/// </summary>
		String TransientDataPath { get; set;}

		/// <summary>
		/// Path to the <c>MarkedData</c> collection
		/// </summary>
		String MarkedDataPath { get; set;}

        /// <summary>
        /// Path to the <c>InvalidData</c> collection
        /// </summary>
        String InvalidDataPath { get; set;}

	    /// <summary>
	    /// Path to the <c>ErrorMessageKeyData</c> collection
	    /// </summary>
        String ErrorMessageKeyDataPath
        {
            get; set;
        }

        String DataProviderPath { get; set;}

	    /// <summary>
        /// If path is specified, the controller will put to the path readonly List 
        /// corresponding with data were loaded for the current page
	    /// </summary>
        String PageDataPath { get; set;}

	    /// <summary>
	    /// Path for IControllerCommand instance
	    /// </summary>
        String CommandPath { get; set;}

		/// <summary>
		/// Not synchronized, not sorted list of the transient entities
		/// This collection`s store in the <c>ControllerContext</c> if there isn`t <c>TransientDataPath</c>
		/// </summary>
		ISet TransientData { get;}

		/// <summary>
		/// Not synchronized, list of the marked entities
		/// This collection`s store in the <c>ControllerContext</c> if there isn`t <c>MarkedDataPath</c>
		/// </summary>
		ISet MarkedData { get;}

		/// <summary>
		/// Data of the last loaded grid`s datasource.
		/// This cache is active only if <c>IsAllowTransient</c> set to <c>true</c>
		/// This cache stored in the <c>ControllerContext</c>
		/// </summary>
		IList GridSourceCache { get;}

	    /// <summary>
	    /// Contains collection if invalid entities
	    /// </summary>
        ISet InvalidData { get;}

        ISet PageData { get;}
        
	    /// <summary>
	    /// Contains error message keys that explain why object was set into InvalidData collection.
	    /// Key - object, Value - ISet contained message keys.
	    /// </summary>
        IDictionary ErrorMessageKeyData { get;}
		
	    /// <summary>
		/// Not synchronized dictionary from page scope
		/// </summary>
		IDictionary ControllerContext { get;}

        IDataProvider CurrentDataProvider { get;}

		/// <summary>
		/// Load data (bind first page, default sort order etc.) by new <c>IFilterState</c> at the specified path 
		/// or refresh data if there is no valid <c>IFilterState</c> at the specified path
		/// </summary>
		void LoadOrRefresh();

        void LoadNewData();

        void Refresh();

		/// <summary>
		/// Bind current page sorted by specified expression
		/// or all pages if <c>grid.AllowPaging</c> is false
		/// or empty <c>ICollection</c> if there is`t data
		/// </summary>
	    void Sort(String sortExpression);

		/// <summary>
		/// Bind page with specified number if number is between first and last page
		/// and first page if number is less then 1 and last page if number is greater than last page number
		/// or all pages if <c>grid.AllowPaging</c> is false
		/// or empty <c>ICollection</c> if there is`t data
		/// </summary>
		void LoadPage(int pageNumber);

        bool Validate();

	    /// <summary>
	    /// Automatic attachment objects to NHibernate session
	    /// </summary>
        bool AutoAttach { get; }
	}
}
